package com.qpx.eurekaconsumerribbon.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qpx.dto.UserDto;
import com.qpx.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/user/list")
    @HystrixCommand(fallbackMethod = "getUserListFallback")
    public ResultEntity getUserList(UserDto userDto){

        HttpEntity httpEntity = new HttpEntity(userDto);
        ResultEntity body = restTemplate.postForEntity("http://EUREKA-PRODUCER/user/list", httpEntity, ResultEntity.class).getBody();
        return body;
    }

    public ResultEntity  getUserListFallback(UserDto userDto){
        return ResultEntity.error("10001","查询用户列表失败");
    }
}
